package com.ruoyi.chatgpt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.chatgpt.domain.GptCatalog;
import com.ruoyi.chatgpt.service.IGptCatalogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 目录Controller
 * 
 * @author ruoyi
 * @date 2023-06-30
 */
@RestController
@RequestMapping("/chatgpt/catalog")
public class GptCatalogController extends BaseController
{
    @Autowired
    private IGptCatalogService gptCatalogService;

    /**
     * 查询目录列表
     */
    @PreAuthorize("@ss.hasPermi('chatgpt:catalog:list')")
    @GetMapping("/list")
    public TableDataInfo list(GptCatalog gptCatalog)
    {
        startPage();
        List<GptCatalog> list = gptCatalogService.selectGptCatalogList(gptCatalog);
        return getDataTable(list);
    }

    /**
     * 导出目录列表
     */
    @PreAuthorize("@ss.hasPermi('chatgpt:catalog:export')")
    @Log(title = "目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GptCatalog gptCatalog)
    {
        List<GptCatalog> list = gptCatalogService.selectGptCatalogList(gptCatalog);
        ExcelUtil<GptCatalog> util = new ExcelUtil<GptCatalog>(GptCatalog.class);
        util.exportExcel(response, list, "目录数据");
    }

    /**
     * 获取目录详细信息
     */
    @PreAuthorize("@ss.hasPermi('chatgpt:catalog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gptCatalogService.selectGptCatalogById(id));
    }

    /**
     * 新增目录
     */
    @PreAuthorize("@ss.hasPermi('chatgpt:catalog:add')")
    @Log(title = "目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GptCatalog gptCatalog)
    {
        return toAjax(gptCatalogService.insertGptCatalog(gptCatalog));
    }

    /**
     * 修改目录
     */
    @PreAuthorize("@ss.hasPermi('chatgpt:catalog:edit')")
    @Log(title = "目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GptCatalog gptCatalog)
    {
        return toAjax(gptCatalogService.updateGptCatalog(gptCatalog));
    }

    /**
     * 删除目录
     */
    @PreAuthorize("@ss.hasPermi('chatgpt:catalog:remove')")
    @Log(title = "目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gptCatalogService.deleteGptCatalogByIds(ids));
    }
}
